package CollectionTest.Homework;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/*
2.已知数组存放一批QQ号码，QQ号码最长为11位，最短为5位String[] strs = {"12345","67891","12347809933","98765432102","67891","12347809933"}。
将该数组里面的所有qq号都存放在LinkedList中，将list中重复元素删除，将list中所有元素分别用迭代器和增强for循环打印出来。
 */
public class Test2 {
    public static void main(String[] args){
        String[] strings = {"12345","67891","12347809933","98765432102","67891","12347809933"};
        List<String> stringList = new LinkedList<>();
        for(int i = 0; i < strings.length; i++){
            stringList.add(strings[i]);
        }
        //使用循环找出集合中重复元素
        for(int x = 0; x < stringList.size(); x++){
            for(int y = x+1; y < stringList.size(); y++){
                if(stringList.get(x).equals(stringList.get(y))){ //使用get方法获取元素进行比较
                    stringList.remove(y);
                }
            }
        }
        //迭代器循环遍历
        Iterator<String> it = stringList.iterator();
        while(it.hasNext()){
            String s = it.next();
            System.out.println(s);
        }
        System.out.println("==========================");
        //增强for遍历
        for(String s : stringList){
            System.out.println(s);
        }
    }
}
